<?php
if (!defined("OK")) { header("location: ../"); }
if(isset($url['k']) && isnum($url['k']) && $url['k'] > 0) { $kid = (int)$url['k']; } else { $kid = 0; }
if(isset($url['m']) && isnum($url['m']) && $url['m'] > 0) { $mid = (int)$url['m']; } else { $mid = 0; }

if ($conf['Palaikymas'] == 1) { klaida("Remontas",$conf['Maintenance'],"Svetainė uždaryta"); }

$text = '';
// Jei paspaudziamas linkas "Komenatarai"
if ($kid != 0) {
	$sql = mysql_fetch_assoc(mysql_query1("SELECT * FROM naujienos WHERE id=".escape($kid).""));
	if (mysql_affected_rows() > 0 && $sql['kom'] == 'taip') {
		lentele($sql['pavadinimas'],$sql['naujiena']);
		if (!empty($sql['daugiau'])) { lentele("Plačiau",$sql['daugiau']); }
		//Rodom komentarus
		include("priedai/komentarai.php");
		komentarai($kid);
	}
	else { klaida("Klaida","Tokios naujienos nėra arba ji buvo ištrinta"); redirect("?id,50","meta"); }
}

// Jei niekas nepaspaudziama, o atidaromas pirminis puslapis
elseif ($kid == 0) {
	echo "
			<table width=\"100%\" border=\"0\" cellpadding=\"0\">
				<tr>
				<td valign='top' width=\"33%\">";
				//Balsavimas
				lentele("Balsavimas","1. Pirma vieta<br/>2. Vieta<br/> 3. Vieta<br/> 4. Vieta<br/> 5. Vieta<br/>");
			echo "
				</td>
				<td valign='top' width=\"33%\">";
				$sql = mysql_query1("SELECT `id`,`tid`,`pav` FROM `d_straipsniai` ORDER BY `d_straipsniai`.`last_data` DESC LIMIT 0,5");
				while ($row = mysql_fetch_assoc($sql)) {					$text .= "<a href='?id,25;t," . $row['tid'] .";s," . $row['id'] ."'>" . $row['pav'] ."</a><br/>";
				}
				lentele("Naujausi Forumo pranešimai",$text);
				$text = '';
			echo "
				</td>
				<td valign='top' width=\"33%\">";

				$sql = mysql_query1("SELECT `id`,`pid`,`pav` FROM `straipsniai` WHERE rodoma='TAIP' ORDER BY `straipsniai`.`id` DESC LIMIT 0,5");
				while ($row = mysql_fetch_assoc($sql)) {
					$text .= "<a href='?id,22;p," . $row['pid'] .";t," . $row['id'] ."'>" . $row['pav'] ."</a><br/>";
				}
				lentele("Naujausi Straipsniai",$text);
				unset($text,$sql);

			echo "
				</td>
				</tr>
			</table>
			";	
		$sql = mysql_query1("
	SELECT
	`naujienos`.`id`,
	`naujienos`.`pavadinimas`,
	`naujienos`.`naujiena`,
	`naujienos`.`data`,
	`naujienos`.`autorius`,
	`naujienos`.`kom`,
	(SELECT COUNT(*) AS `kiek` FROM `kom` WHERE `pid`='50' AND `kom`.`kid` = `naujienos`.`id`) AS `viso`
	FROM
	`naujienos`
	ORDER BY
	`naujienos`.`data` DESC
");
	while ($row = mysql_fetch_assoc($sql)) {		$extra = "<div class='sarasas' style='text-align: right'>".(($row['kom'] == 'taip')?"<a href='?id,50;k," . $row['id'] ."'>Komentarai (" . $row['viso'] .")</a> ":"")."</div>";
		lentele("Parašė: ".$row['autorius']." - ".$row['pavadinimas'],$row['naujiena']." " . $extra);
	}
	unset($text,$sql,$row,$extra);
}

?>

